package store.dao.daoImpl;

import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import store.dao.CategoryDao;
import store.domain.Category;
import store.utils.JDBCUtils;

public class CategoryDaoImpl implements CategoryDao {

	@Override
	public List<Category> getAllCates() throws Exception {
		String sql = "select * from category";
		QueryRunner queryRunner = new QueryRunner(JDBCUtils.getDataSource());
		List<Category> list = queryRunner.query(sql, new BeanListHandler<Category>(Category.class));
		
		return list;
	}

	@Override
	public void addCategory(Category category) throws Exception {

		String sql = "insert into category values (?,?)";
		QueryRunner queryRunner = new QueryRunner(JDBCUtils.getDataSource());
		queryRunner.update(sql,category.getCid(),category.getCname());
	}

}
